<template>
  <div class="box">
    <div class="bg"></div>
    <van-nav-bar
      id="van-bar"
      :title="title"
      fixed
      :border="border"
      left-arrow
      @click-left="onClickLeft"
    >
      <template #left>
        <img
          :style="{ width: widthPx, height: heightPx }"
          src="@/assets/iconPerfectInformation/nav_back@2x.png"
        />
      </template>
    </van-nav-bar>
    <div
      :style="
        'margin-top:' +
        topheight +
        'px;height:calc(100vh - ' +
        topheight +
        'px);width:100%;overflow:auto;'
      "
    >
      <div class="blacklist">
        <div class="list" v-for="(item, index) in list" :key="index">
          <span class="name">{{ item.name }}</span>
          
          <span class="vip" v-if="item.isvip">VIP</span>
          <van-switch v-model="item.istrue" size="10px" @change="editSetting(index)" style="margin: 5px 0;float: right;"/>
        </div>
        <!-- <p style="text-align: center;margin: 24px 0;color: #AAAAAA;font-size: 10px;">— THE END —</p> -->
      </div>
    </div>
  </div>
</template>

<script>
import {SetSetting, getSetting} from "@/api/setting"

export default {
  data() {
    return {
      border: "",
      widthPx: "28px",
      heightPx: "28px",
      topheight: 0,
      isActive: 0,
      title: "隐私设置",
      list: [
        {
          name: "距离展示保密",
          istrue: false,
          isvip:false
        },
        {
          name: "隐身访问",
          istrue: false,
          isvip:true
        },
      ],
    };
  },
  mounted() {
    this.topheight = document.getElementById("van-bar").offsetHeight;
    this.getSetting1()
  },

  methods: {
    
    onClickLeft() {
      this.$router.back();
    },
  
  getlist(){
    console.log(1);
  },
  getSetting1(){
             getSetting(
            ).then((res) => {
              this.list[0].istrue=res.data.is_distance==1?true:false
              this.list[1].istrue=res.data.is_stealth==1?true:false
          
              console.log(res);
      
      })
    },
    editSetting(index){
              let data={}
        if (index==0) {
          data.is_distance=this.list[0].istrue?1:0

          
        }else if(index==1){
          
           data.is_stealth=this.list[1].istrue?1:0

         
        }
        
      console.log(data);
             SetSetting({...data}
            ).then((res) => {
              console.log(1);
            this.getSetting1()
      
      }).catch(()=>{
            this.getSetting1()

      })
    }
    }
};
</script>

<style scoped>
.blacklist {
  width: 345px;
  margin: 0 auto;
}
.headImg {
  width: 40px;
  height: 40px;
}
.list {
  padding: 16px 0;
  border-bottom: #D8D8D8 solid 1px;
}
.list span {
  display: inline-block;
  vertical-align: top;
}
.name{
  margin: 0 7px;
  font-size: 14px;
font-family: PingFangSC, PingFang SC;
font-weight: 600;
color: #1A1A1A;

}

.vip {
width: 54px;
height: 16px;
background: linear-gradient(180deg, #E8B87A 0%, #FDE0B9 100%);
border-radius: 8px;
  text-align: center;
  line-height: 17px;
  vertical-align: top;
  font-size: 12px;
  color: #663409;
}

.van-cell {
  background-color: transparent;
}
.van-cell::after {
  border-color: #d8d8d8;
}
.van-cell__value {
  color: #1a1a1a;
  font-weight: 500;
}
</style>
